def jeep_plan(total_dist=1000.0, capacity=500.0):
    segments = []
    remaining = total_dist
    k = 1
    while True:
        if remaining <= capacity:
            d = remaining
            factor = 1.0
            fuel_used = factor * d
            segments.append((k, d, factor, fuel_used))
            break
        factor = 2 * k - 1
        d = capacity / factor
        if d > remaining:
            d = remaining
            factor = 1.0
            fuel_used = factor * d
            segments.append((k, d, factor, fuel_used))
            break
        fuel_used = factor * d
        segments.append((k, d, factor, fuel_used))
        remaining -= d
        k += 1
    total_fuel = sum(seg[3] for seg in segments)
    return segments, total_fuel
def main():
    total_dist = 1000.0
    capacity = 500.0
    segments, total_fuel = jeep_plan(total_dist, capacity)
    print(f"总路程：{total_dist} km，油箱+载油容量：{capacity} gal，单位耗油率：1gal/km\n")
    print("分段结果（近似最优策略）：")
    cur_pos = 0.0
    for k, d, factor, fuel_used in segments:
        start = cur_pos
        end = cur_pos + d
        print(f"阶段{k}: 从{start:.2f}km到{end:.2f} km，长度 ≈ {d:.2f}km")
        print(f"等效耗油倍率 ≈ {factor:.2f}，该段耗油 ≈ {fuel_used:.2f} gal\n")
        cur_pos = end
    print(f"最少总耗油量（从起点无限油源取走的油总和）≈ {total_fuel:.2f}gal")
if __name__ == "__main__":
    main()
